package com.tongguan.paypos.common;

import android.text.TextUtils;

import com.tongguan.paypos.R;
import com.tongguan.paypos.entity.PayType;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Joylive on 2016/10/17 .
 */

public class AppConstants {

    public static final String UNION_PAY_APP_PACKAGE = "cn.basewin.unionpay.tongguan";//银联app 包名
    public static final String UNION_PAY_APP_MAIN = "cn.basewin.unionpay.ui.SignInAty";//银联app 主页
    public static final String LAUNCHER_APP_STORE = "cn.appstore.basewin";//应用市场

    public static final String APPLICATIONID = "cn.basewin.unionpay";
    public static final String BASE_DIR = "cn.basewin.unionpay.external.";
    public static final String SIGN_DIR = BASE_DIR + "SignExternalAty";//登录
    public static final String SALE_DIR = BASE_DIR + "SaleExternalAty";//消费
    public static final String VOID_DIR = BASE_DIR + "VoidExternalAty";//撤销
    public static final String REFUND_DIR = BASE_DIR + "RefundExternalAty";//退货
    public static final String PRINT_DIR = BASE_DIR + "MenuExternalAty";//打印
    public static final String PRINT_LAST_DIR = BASE_DIR + "PrintLastExternalAty";//打印最后一笔
    public static final String QUERYBALANCE_DIR = BASE_DIR + "QueryBalanceExternalAty";//查询
    public static final String SETTLEMENT_DIR = BASE_DIR + "SettlementExternalAty";//结算
    public static final String SYSMANAGEMENT_DIR = BASE_DIR + "SysManageExternalAty";//设置
    public static final String GETCARD_DIR = BASE_DIR + "GetCardExternalAty";//获取卡号
    public static final String GETSN_DIR = BASE_DIR + "GetSNExternalAty";//获取SN号

    public static final int MONEY_LIMIT_PAY = 0;//输入限制金额

    // sp 键值对 key字段
    public final static String NEEDCALLBACK = "NeedCallback";//
    public final static String REMEMBER = "remember";//
    public final static String LOGIN_NAME = "loginName";//
    public final static String LOGIN_PWD = "loginPwd";//
    public final static String IMG_CACHE = "imgCache";//
    public final static String DEVICE_SN = "deviceSn";//
    public final static String EVERYDAY_SIGN_IN = "everydaySignIn";//
    public final static String SAVE_XL_MER = "saveXLMer";//
    public final static String SAVE_XL_TERM = "saveXLTerm";//
    public final static String XL_ACTIVE = "active";// 迅联激活w
    public final static String XL_DOWNLOAD_PARAMS = "downloadParams";//迅联下载参数
    public final static String XL_RAS = "ras";//迅联下载密钥
    public final static String XL_SIGN_IN = "signIn";//迅联签到过
    public final static String SWITCH_XL = "switchXL";//迅联开关
    public final static String SWITCH_SD = "switchSD";//闪电打印
    public final static String NET_CONNECT_TYPE = "netConnectType";//网络连接方式 0 默认  1 正式  2测试 3 域名
    public final static String CAMERA_TYPE = "cameraType";//摄像头设置方式  0 后置 1前置
    public final static String CRASH = "crash";//设置异常信息配置
    public final static String DOWNLOAD_KEY = "isDownloadKey";//是否下载过签名
    public final static String SIGNATURE = "signature";// 签名

    public final static String CACHE_DIR = "/data/data/com.tongguan.paypos.p2l/cache/";//user 缓存包名 （不同的应用包名要更改）

    public final static Map<String, PayType> payTypeMap = new HashMap<String, PayType>();
    public final static Map<String, String> orderState = new HashMap<String, String>();
    public final static Map<String, String> transType = new HashMap<String, String>();// 交易状态

    public static Map<String, String> errorCode = new HashMap<>();//消费、撤销错误码 外卡
    public static Map<String, String> processFlag = new HashMap<>();//交易处理标志外卡
    public static Map<String, String> revFlag = new HashMap<>();//交易冲正标志 外卡

    static {
        payTypeMap.put("WX", new PayType(0, "WX", "微信支付", R.drawable.icon_pay_wx));
        payTypeMap.put("ZFB", new PayType(1, "ZFB", "支付宝支付", R.drawable.icon_pay_zfb));
        payTypeMap.put("YZF", new PayType(2, "YZF", "翼支付", R.drawable.icon_easypay));
        payTypeMap.put("XJ", new PayType(3, "XJ", "现金支付", R.drawable.icon_pay_cash));
        payTypeMap.put("HYC", new PayType(4, "HYC", "会员卡支付", R.drawable.icon_padpay));
        payTypeMap.put("QQ", new PayType(5, "QQ", "QQ钱包支付", R.drawable.icon_pay_qq));
        payTypeMap.put("POS", new PayType(6, "YL", "刷卡支付", R.drawable.icon_pay_pos));
        payTypeMap.put("JF", new PayType(7, "JF", "积分支付", R.drawable.icon_pay_jf));
        payTypeMap.put("DK", new PayType(8, "DK", "代扣支付", R.drawable.icon_pay_daikou));
        payTypeMap.put("WK", new PayType(9, "XL", "外卡支付", R.drawable.icon_pay_pos_wk));
        payTypeMap.put("YLSM", new PayType(10, "YLSM", "银联扫码", R.drawable.icon_unionpay_wallet));


        orderState.put("0", "支付成功");
        orderState.put("1", "支付失败");
        orderState.put("2", "已撤销");
        orderState.put("3", "已冲正");
        orderState.put("4", "待支付");
        orderState.put("5", "已转入退款");

        transType.put("0", "消费");
        transType.put("1", "消费");
        transType.put("2", "消费撤销");
        transType.put("3", "消费");
        transType.put("4", "消费");
        transType.put("5", "消费退款");

        //-----------------外卡-----------------------------
        errorCode.put("01", "01交易失败-请联系客服");
        errorCode.put("02", "02交易失败-请联系客服");
        errorCode.put("03", "03无效商户-请联系客服");
        errorCode.put("04", "04卡片异常-请联系客服或换卡重试");
        errorCode.put("05", "05交易失败-请联系客服");
        errorCode.put("06", "06交易失败-请联系客服");
        errorCode.put("07", "07卡片异常-请联系客服或换卡重试");
        errorCode.put("09", "09请重新操作");
        errorCode.put("12", "12无效交易-请联系客服");
        errorCode.put("13", "13无效金额-请联系客服");
        errorCode.put("14", "14无效卡号-请联系客服或换卡重试");
        errorCode.put("15", "15无此发卡行-请联系客服或换卡重试");
        errorCode.put("19", "19交易失败-请重试");
        errorCode.put("20", "20交易失败-请联系客服");
        errorCode.put("21", "21交易失败-请联系客服");
        errorCode.put("22", "22操作有误-请重试"); //重新签到
        errorCode.put("23", "23交易失败-请联系客服");
        errorCode.put("25", "25无效交易-请联系客服");
        errorCode.put("30", "30格式错误-请联系客服");
        errorCode.put("31", "31银行未联网-请联系客服");
        errorCode.put("33", "33过期卡-请换卡重试");
        errorCode.put("34", "34卡片异常-请换卡重试");
        errorCode.put("35", "35卡片异常--请换卡重试");
        errorCode.put("36", "36卡片异常--请换卡重试");
        errorCode.put("37", "37卡片异常-请换卡重试");
        errorCode.put("38", "38密码错误次数超限");
        errorCode.put("39", "39交易失败-请重试");
        errorCode.put("40", "40不支持的交易类型");
        errorCode.put("41", "41卡片异常-请换卡重试");
        errorCode.put("42", "42卡片异常-请联系客服");
        errorCode.put("43", "43卡片异常-请换卡重试");
        errorCode.put("44", "44交易失败-请联系客服或换卡重试");
        errorCode.put("45", "45IC卡不允许降级使用");
        errorCode.put("51", "51余额不足");
        errorCode.put("52", "52交易失败-请联系客服");
        errorCode.put("53", "53交易失败-请联系客服");
        errorCode.put("54", "54过期卡-请换卡重试");
        errorCode.put("55", "55密码错误-请重试");
        errorCode.put("56", "56交易失败-请联系客服");
        errorCode.put("57", "57未授权的交易-请联系客服");
        errorCode.put("58", "58未授权的交易-请联系客服");
        errorCode.put("59", "59交易失败-请联系客服");
        errorCode.put("60", "60交易失败-请联系客服");
        errorCode.put("61", "61超交易限额-请联系客服或换卡重试");
        errorCode.put("62", "62卡片异常-请换卡重试");
        errorCode.put("63", "63交易失败-请联系客服");
        errorCode.put("64", "64原金额错误-请联系客服或重试");
        errorCode.put("65", "65超交易次数-请联系客服");
        errorCode.put("66", "66交易失败-请联系客服");
        errorCode.put("67", "67卡片异常-请换卡重试");
        errorCode.put("68", "68交易超时-请重试");
        errorCode.put("75", "75密码错误次数超限");
        errorCode.put("77", "77交易失败-请联系客服"); //重新签到
        errorCode.put("78", "78-交易失败-请联系客服");
        errorCode.put("79", "79对账不平-请联系客服");
        errorCode.put("80", "80交易失败-请联系客服");
        errorCode.put("81", "81交易失败-请联系客服");
        errorCode.put("83", "83交易失败-请联系客服");
        errorCode.put("84", "84交易失败-请联系客服");
        errorCode.put("85", "85交易失败-请联系客服");
        errorCode.put("86", "86交易失败-请联系客服");
        errorCode.put("88", "87交易失败-请联系客服");
        errorCode.put("89", "80交易失败-请联系客服");
        errorCode.put("90", "90交易失败-请稍后重试");
        errorCode.put("91", "91交易失败-请联系客服");
        errorCode.put("92", "92交易失败-请联系客服");
        errorCode.put("93", "93交易失败-请联系客服");
        errorCode.put("94", "94重复交易"); //重新签到
        errorCode.put("95", "95交易失败-请联系客服");
        errorCode.put("96", "96交易失败-请联系客服");
        errorCode.put("97", "97无效终端-请联系客服或检查配置");
        errorCode.put("98", "98交易超时-请重试");
        errorCode.put("99", "99交易失败-请联系客服");//重新签到
        errorCode.put("A0", "A0请重新签到或联系客服"); //重新签到

        processFlag.put("0", "成功");
        processFlag.put("1", "受理方拒绝");
        processFlag.put("2", "转发方失败");
        processFlag.put("3", "渠道拒绝");//扫码交易，查询失败后超时选择该状态，表示该笔09应答码交易是失败交易
        processFlag.put("4", "超时");
        processFlag.put("5", "处理中");
        processFlag.put("6", "落地");

        revFlag.put("0", "消费");
        revFlag.put("1", "冲正");
        revFlag.put("2", "撤销");
        revFlag.put("3", "退货");
        revFlag.put("4", "汇款");
        revFlag.put("5", "完成");
        revFlag.put("6", "手工退货");
        revFlag.put("7", "手工完成");
        revFlag.put("8", "手工撤销");
    }

    /**
     * 获取支付方式
     */
    public static String getPayTypeText(String channelId) {
        String def;
        switch (channelId) {
            case "WX":
                def = "微信支付";
                break;
            case "ZFB":
                def = "支付宝支付";
                break;
            case "YZF":
                def = "翼支付";
                break;
            case "XJ":
                def = "现金支付";
                break;
            case "YL":
                def = "刷卡支付";
                break;
            case "QQ":
                def = "QQ钱包支付";
                break;
            case "HYC":
                def = "会员卡支付";
                break;
            case "JF":
                def = "积分支付";
                break;
            case "DK":
                def = "代扣支付";
                break;
            case "YLSM":
                def = "银联钱包支付";
                break;
            default:
                def = "未知支付方式 " + channelId;
                break;
        }
        return def;
    }

    /**
     * 消息过滤
     */
    public static boolean messageFilter(String message) {
        if (TextUtils.isEmpty(message)){
            return false;
        }
        boolean def;
        switch (message) {
            case "订单已关闭或取消":
                def = true;
                break;
            case "验证签名错误":
                def = true;
                break;
            case "商户尚未开通银联扫码支付":
                def = true;
                break;
            case "付款码错误或过期":
                def = true;
                break;
            default:
                def = false;
                break;
        }
        return def;
    }

}
